﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharp.Libs.WPF.UserControls.SmartMediaPlayer.Models
{
    /// <summary>
    /// 
    /// </summary>
    /// <history>modiefied 22.07.2014 added Last Position</history>
    public class PlaylistItem : ViewModelBase
	{
		#region static functions
		public static bool TryParse(
			DataRow dr, 
			out PlaylistItem pi)
		{
			try
			{
				pi = new PlaylistItem();
				pi.Id = (long)dr["id"];
				pi.Filename = dr["Filename"].ToString();
				pi.SortOrder = (long)dr["SortOrder"];
				if (dr.Table.Columns.Contains("Position"))
				{
					pi.LastPosition = (long)dr["Position"];
				}
				else
				{
					pi.LastPosition = (long)0;
				}
			}
			catch 
			{
				pi = null;
				return false;
			}

			return true;
		}
		#endregion



		#region properties
		private long _intId;
		public long Id
		{
			get { return _intId; }
			set
			{
				_intId = value;
				OnPropertyChanged("Id");
			}
		}

		private string _strFilename;

		public string Filename
		{
			get { return _strFilename; }
			set
			{
				_strFilename = value;
				OnPropertyChanged("Filename");
			}
		}


		private long _intSortOrder;
		public long SortOrder
		{
			get { return _intSortOrder; }
			set
			{
				_intSortOrder = value;
				OnPropertyChanged("SortOrder");
			}
		}

        private long _intLastPosition;
        public long LastPosition
        {
            get { return _intLastPosition; }
            set
            {
                _intLastPosition = value;
                OnPropertyChanged("LastPosition");
            }
        }

		#endregion
	}
}
